/*
 *
 *
 */
#pragma semicolon 1
#pragma newdecls required
 
#include <sourcemod>
#include <sdktools>
int g_Attacker[MAXPLAYERS+1];

int  g_BoomerDmgEnable;
ConVar hCvar_BoomerDmgEnable;


#define PLUGIN_VERSION "1.0"

public Plugin myinfo =
{
	name = "l4d2_boomer_kill_survivor",
	author = "ヾ藤野深月ゞ",
	description = "玩家被boomer喷或炸中胆汁，直接秒杀玩家",
	version = PLUGIN_VERSION,
	url = "https://gitee.com/sweet-and-sour-bombs/adfvsdsd"
};

public void OnPluginStart()
{
	RegAdminCmd("sm_ms", Command_BoomerSwitch, ADMFLAG_KICK, "秒杀插件总开关");
	RegAdminCmd("sm_danzhi", Command_BoomerSwitch, ADMFLAG_KICK, "Boomer喷胆汁秒杀指令开关");
	hCvar_BoomerDmgEnable = CreateConVar("tank_boomerdamage_enable", "1", "是否启用Boomer喷胆汁秒杀插件", FCVAR_NOTIFY, true, 0.0, true, 1.0);
	
	
	HookConVarChange(hCvar_BoomerDmgEnable, eConvarChanged);	
	HookEvent("player_now_it", HandlePlayerNowIt, EventHookMode_Pre); //玩家被喷胆汁

}

public void OnMapStart()
{
	CvarsChanged();
}

public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
	CvarsChanged();
}

void CvarsChanged()
{
	g_BoomerDmgEnable = hCvar_BoomerDmgEnable.IntValue;

}

public Action Command_BoomerSwitch(int client, int args)
{
	if (g_BoomerDmgEnable)
	{
		hCvar_BoomerDmgEnable.IntValue = 0;
		PrintToChat(client, "\x04[提示]\x05Boomer喷胆汁秒杀插件已\x03关闭\x05.");
	}
	else
	{
		hCvar_BoomerDmgEnable.IntValue = 1;
		PrintToChat(client, "\x04[提示]\x05Boomer喷胆汁秒杀插件已\x03开启\x05.");
	}
	return Plugin_Handled;
}

//玩家被喷胆汁
public void HandlePlayerNowIt(Event event, const char[] name, bool dontBroadcast)
{



	int victim = GetClientOfUserId(GetEventInt(event, "userid"));
	int attacker = GetClientOfUserId(GetEventInt(event, "attacker")); 
	if (!victim) return;
	if (!attacker) return;

	g_Attacker[attacker] = victim;
	
	if(g_BoomerDmgEnable == 1)
	{
		PrintToChatAll("\x04[提示]\x03Boomer%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
		ForcePlayerSuicide(victim);
	}			
}



char[] GetTrueName(int client)
{
	char sName[32];
	int Bot = IsClientIdle(client);

	if(Bot != 0)
		FormatEx(sName, sizeof(sName), "闲置:%N", Bot);
	else
		GetClientName(client, sName, sizeof(sName));
	return sName;
}

int IsClientIdle(int client) 
{
	if (!HasEntProp(client, Prop_Send, "m_humanSpectatorUserID"))
		return 0;

	return GetClientOfUserId(GetEntProp(client, Prop_Send, "m_humanSpectatorUserID"));
}

char[] GetPlayerName(int client, bool bPromptType)
{
	char sName[32];
	if (!IsFakeClient(client) && IsPlayerAlive(client) && GetClientTeam(client) == 3 && GetEntProp(client, Prop_Send, "m_zombieClass"))
		FormatEx(sName, sizeof(sName), "%s%N", !bPromptType ? "" : "\x04", client);
	else
	if (!IsFakeClient(client) && !IsPlayerAlive(client) && GetClientTeam(client) == 3 && GetEntProp(client, Prop_Send, "m_zombieClass"))
		FormatEx(sName, sizeof(sName), "%s%N", !bPromptType ? "" : "\x04", client);	
	return sName;
}



















